package Demo05;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—05—16
 * Time: 20:47
 */
class Student implements Comparable<Student>{
    public String name;
    public int age;
    public double score;

    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Student o) {
/*        if(this.age > o.age) {
            return 1;
        }else if(this.age == o.age) {
            return 0;
        }else {
            return -1;
        }*/
        return this.age - o.age;
    }
}


public class Test07 {

    public static void main(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("zhang san",22,60);
        students[1] = new Student("li si",21,70);
        students[2] = new  Student("wang wu",21,80);
        System.out.println("排序前" + Arrays.toString(students));
        Arrays.sort(students);
        System.out.println("排序后" + Arrays.toString(students));
    }


/*    public static void main(String[] args) {
        Student student = new Student("zhang san",20,60);
        Student student1 = new Student("li si",21,70);
        Student student2 = new  Student("wang wu",21,80);
        if(student.compareTo(student1) > 0){
            System.out.println("student > student1");
        }else if (student.compareTo(student1) == 0){
            System.out.println("student == student1");
        }else {
            System.out.println("student < student1");
        }
    }*/
}
